import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.List;
import java.util.StringTokenizer;


public class Main {

	public static void main(String[] args) throws IOException {
		PersonList list = new PersonList();
		Person front = null;
		Person temp = null;
		CalcTest test = new CalcTest();
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String str = reader.readLine();
		int total = Integer.parseInt(str);
		String[] personDescs = new String[total];
		for (int i = 0; i < total; i++) {
			
			personDescs[i] = reader.readLine();
			Person p = null;
			String[] nums = personDescs[i].split(" ");
			if (nums[0].startsWith("0")) {
				p = new Staff(null);
				int number = Integer.parseInt(nums[1]);
				ArrayList skills = new ArrayList(number);
				for (int j = 2; j < nums.length; j++) {
					skills.add(Integer.parseInt(nums[j]));
				}
				((Staff) p).setSkills(skills);
			} else {
				p =new Leader(null);
				int number = Integer.parseInt(nums[1]);
				ArrayList demands = new ArrayList(number);
				for (int j = 2; j < nums.length; j++) {
					Demand demand = new Demand(Integer.parseInt(nums[j++]), Integer.parseInt(nums[j]));
					demands.add(demand);
				}
			}
			
			if (i == 0) {
				front = p;
				temp = p;
				list.setFront(front);
			} else {
				temp.setNext(p);
				temp = p;
			}
			
		}
		System.out.println("ddd");
		
//		ElementList[] lists = new ElementList[total];
//		for (int k = 0; k < total; k++) {
//			lists[k] = new ElementList();
//			Person first = new Person(arrays[k][0]);
//			Person temp = first;
//			for (int p = 1; p < arrays[k].length; p++) {
//				Person e = new Person(arrays[k][p]);
//				temp.setNext(e);
//				if (p == arrays[k].length - 1) {
//					e.setNext(first);
//				}
//				temp = e;
//			}
//			lists[k].setFront(first);
//		}
//		 
//		int maxValue = 0;
//		for (int k = 0; k < total; k++) {
//			if (!test.inital(lists[k])) {
//				System.out.println(lists[k].getTotal());
//			} else {
//				maxValue = test.getMaxValue(lists[k]);
//				Person front = lists[k].getFront();
//				while (test.hasFront(lists[k])) {
//					if (front == lists[k].getFront()) {
//						break;
//					}
//					int max = test.getMaxValue(lists[k]);
//					maxValue = maxValue >= max ? maxValue : max;
//				}
//				System.out.println(maxValue);
//			}
//		}
//		
	}
	
}

class CalcTest {
	
//	public boolean inital(ElementList list) {
//		Person front = list.getFront();
//		Person temp = front.getNext();
//		while (temp != front) {
//			if (temp.getValue() < 0 && temp.getNext().getValue() >= 0) {
//				list.setFront(temp);
//				return true;
//			}
//			temp = temp.getNext();
//		}
//		
//		if (front.getValue() < 0 && front.getValue() >= 0) {
//			return true;
//		}
//		
//		return false;
//	}
//	
//	public boolean hasFront(ElementList list) {
//		Person front = list.getFront();
//		Person temp = front.getNext();
//		while (temp.getValue() >= 0 && temp != front) {
//			temp = temp.getNext();
//		}
//		
//		if (temp != front) {
//			list.setFront(temp);
//			return true;
//		} else {
//			return false;
//		}
//	}
//	
//	public int getMaxValue(ElementList list) {
//		int secondMaxValue = 0;
//		int sum = 0;
//		int seqSum = 0;
//		Person front = list.getFront();
//		Person temp = front.getNext();
//		while (temp.getValue() >= 0 && temp != front) {
//			sum += temp.getValue();
//			temp = temp.getNext();
//		}
//		
//		if (temp == front) {
//			return sum;
//		} else {
//			temp = temp.getNext();
//			seq :
//			while (temp != front) {
//				if (temp.getValue() >= 0) {
//					while (temp.getValue() >= 0 && temp != front) {
//						seqSum += temp.getValue();
//						temp = temp.getNext();
//					}
//					secondMaxValue = secondMaxValue >= seqSum ? secondMaxValue : seqSum;
//					seqSum = 0;
//					break seq;
//				} else {
//					temp = temp.getNext();
//				}
//			}
//			
//		}
//		
//		return sum + secondMaxValue;
//	}
	
}

class PersonList {
	
	private Person front;
	
	public boolean hasNext() {
		if (front.getNext() != null) {
			return true;
		} else {
			return false;
		}
	}

	public Person getFront() {
		return front;
	}

	public void setFront(Person front) {
		this.front = front;
	}
	
//	public int getTotal() {
//		 int total = front.getValue();
//		 Person temp = front.getNext();
//		 while (temp != front) {
//			 total += temp.getValue();
//			 temp = temp.getNext();
//		 }
//		 return total;
//	}
	
}

class Person {
	
	private Person next;

	public Person(Person next) {
		this.next = next;
	}
	
	public Person getNext() {
		return next;
	}

	public void setNext(Person next) {
		this.next = next;
	}
	
}

class Staff extends Person {

	private ArrayList skills;
	
	public Staff(Person next) {
		super(next);
	}

	public ArrayList getSkills() {
		return skills;
	}

	public void setSkills(ArrayList skills) {
		this.skills = skills;
	}

}

class Leader extends Person {

	private ArrayList demands; 
	
	public Leader(Person next) {
		super(next);
	}

	public ArrayList getDemands() {
		return demands;
	}

	public void setDemands(ArrayList demands) {
		this.demands = demands;
	}

}


class Demand {
	
	private int skillId;
	
	private int number;
	
	public Demand(int skillId, int number) {
		this.skillId = skillId;
		this.number = number;
	}
}
